# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-alcotest
pkgver=1.5.0
pkgrel=4
_pkgreal=alcotest-js
pkgdesc="Lightweight and colourful test framework"
url="https://github.com/mirage/alcotest"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-astring-dev
	ocaml-cmdliner-dev
	ocaml-fmt-dev
	ocaml-re-dev
	ocaml-stdlib-shims
	ocaml-uutf-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	ocaml-logs-dev
	ocaml-lwt-dev
	"
checkdepends="ocaml-result-dev"
provides="$pkgname-lwt=$pkgver-r$pkgrel"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.bz2::https://github.com/mirage/alcotest/releases/download/$pkgver/alcotest-js-$pkgver.tbz
	test-expected-output.patch
	"
builddir="$srcdir/$_pkgreal-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build \
		-p alcotest,alcotest-lwt \
		@install --no-buffer --verbose
}

check() {
	dune runtest --build-dir=.testenv \
		-p alcotest,alcotest-lwt
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml \
		alcotest alcotest-lwt

	rm -Rf "$pkgdir"/usr/doc
}

dev() {
	default_dev
	provides="$pkgname-lwt-dev=$pkgver-r$pkgrel"

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
1aea91de40795ec4f6603d510107e4b663c1a94bd223f162ad231316d8595e9e098cabbe28a46bdcb588942f3d103d8377373d533bcc7413ba3868a577469b45  ocaml-alcotest-1.5.0.tar.bz2
d379be678e86467573067bac990ea683c627f4d16c1c4d31e7803ab4b5623164f1bf35c908b44e5e434df938b9902a601e998d4e9cd7c4be888e421048b57fda  test-expected-output.patch
"
